package com.zhuss.car.car;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.stereotype.Component;
import org.springframework.transaction.annotation.Transactional;

import com.zhuss.bean.bo.car.car.CreateCarBo;
import com.zhuss.bean.bo.car.car.DeleteCarBo;
import com.zhuss.bean.bo.car.car.StartCarBo;
import com.zhuss.bean.bo.car.car.StopCarBo;
import com.zhuss.bean.bo.car.car.UpdateCarBo;
import com.zhuss.common.OperateService;
import com.zhuss.common.Processor;
import com.zhuss.exception.DzcxException;

/**
 * @description: 车辆操作的Service
 * @author: zhushanshuo
 * @create: Fri Dec 18 20:35:18 CST 2020
 **/
@Component("carOperateService")
public class CarOperateService implements OperateService<Void, Object> {

	@Autowired
	@Qualifier("carCreate")
	private Processor<Object, CreateCarBo> carCreate;

	@Autowired
	@Qualifier("carUpdate")
	private Processor<Object, UpdateCarBo> carUpdate;

	@Autowired
	@Qualifier("carDelete")
	private Processor<Object, DeleteCarBo> carDelete;

	@Autowired
	@Qualifier("carStart")
	private Processor<Object, StartCarBo> carStart;

	@Autowired
	@Qualifier("carStop")
	private Processor<Object, StopCarBo> carStop;


	/**
	 * 创建
	 */
	@Override
    @Transactional(rollbackFor = Exception.class)
	public Void create(Object param) throws DzcxException {

		CreateCarBo bo = (CreateCarBo) param;

		carCreate.process(bo);

		return null;
	}

	/**
	 * 修改
	 */
	@Override
    @Transactional(rollbackFor = Exception.class)
    public Void update(Object param) throws DzcxException {

		UpdateCarBo bo = (UpdateCarBo) param;

		carUpdate.process(bo);

    	return null;
    }

	/**
	 * 删除
	 */
	@Override
	@Transactional(rollbackFor = Exception.class)
	public Void delete(Object param) throws DzcxException {

		DeleteCarBo bo = (DeleteCarBo) param;

		carDelete.process(bo);

		return null;
	}

	/**
	 * 启用
	 */
	@Transactional(rollbackFor = Exception.class)
	protected Void start(Object param) throws DzcxException {

		StartCarBo bo = (StartCarBo) param;

		carStart.process(bo);

		return null;
	}

	/**
	 * 停用
	 */
	@Transactional(rollbackFor = Exception.class)
	protected Void stop(Object param) throws DzcxException {

		StopCarBo bo = (StopCarBo) param;
//
		carStop.process(bo);

		return null;
	}

}

